package com.umgsai.thread.thread53;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

public class Service {
	public ReentrantLock lock = new ReentrantLock();
	public Condition condition = lock.newCondition();
	public void waitMethod() {
		try {
			lock.lock();
			Thread.sleep(Integer.MAX_VALUE);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			lock.unlock();
		}
	}
	public static void main(String[] args) throws InterruptedException {
		final Service service = new Service();
		Runnable runnable = new Runnable() {
			
			@Override
			public void run() {
				service.waitMethod();
			}
		};
		Thread a = new Thread(runnable);
		a.start();
		Thread.sleep(500);
		Thread b = new Thread(runnable);
		b.start();
		Thread.sleep(500);
		System.out.println(service.lock.hasQueuedThread(a));//false 查询指定的线程是否正在等待此锁定
		System.out.println(service.lock.hasQueuedThread(b));//true
		System.out.println(service.lock.hasQueuedThreads());//true 查询是否有线程正在等待此锁
	}
}
